package com.daJiao.handler.wx;

import com.daJiao.service.SysSubscribeUserService;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

/**
 * <p>Title:      UnsubscribeHandler. </p>
 * <p>Description 取消关注事件 </p>
 * <p>Copyright: Copyright (c) 2016</p>
 * <p>Company:    医百科技有限公司 </p>
 *
 * @author         <a href="yangwensheng@100doc.com.cn"/>杨文生</a>
 * @since      2021/2/27 17:17
 */
@Component
public class UnsubscribeHandler extends AbstractHandler {

    @Resource
    private SysSubscribeUserService sysSubscribeUserService;

    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
                                    Map<String, Object> context, WxMpService wxMpService,
                                    WxSessionManager sessionManager) {
        String openId = wxMessage.getFromUser();
        this.logger.info("用户openId={}取消关注,", openId);
        sysSubscribeUserService.deleteByOpenId(openId);
        return null;
    }

}
